public class Solution2 {
    public String longestCommonPrefix(String[] strs) {
        if (strs == null || strs.length <= 0) {
            return "";
        }

        String publicStr = strs[0];
        while (publicStr.length() != 0) {
            boolean flag = true;
            for (int i = 1; i < strs.length; i++) {
                if (!strs[i].startsWith(publicStr)) {
                    publicStr = publicStr.substring(0, publicStr.length() - 1);
                    flag = false;
                    break;
                }
            }

            if (flag) {
                return publicStr;
            }
        }
        return "";
    }
}